package com.powernode.ssm.springAnalysis.a12.def_JDK.d4;


import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

//extends Proxy继承jdk中的父类
public class $Proxy4 extends Proxy implements D4.Foo4 {

      //jdk中Proxy已有该成员变量
    //private InvocationHandler invocationHandler;

    public $Proxy4(InvocationHandler invocationHandler){
        //1
        //调用父类构造方法
        super(invocationHandler);
    }

    static Method foo;
    static Method bar;
    static {
        try {
            foo = D4.Foo4.class.getMethod("foo");
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        }
        try {
            bar = D4.Foo4.class.getMethod("bar");
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        }
    }



    @Override
    public void foo() throws Throwable {
        //获取调用方法的方法对象
        //接口回调，执行增强逻辑，同时把方法对象作为参数传入
        //h为jdk中Proxy成员变量
        h.invoke(this,foo, new Object[0]);
    }

    @Override
    public int bar() throws Throwable {
        //3
        //h为jdk中Proxy成员变量
        int invoke = (int) h.invoke(this,bar, new Object[0]);
        return invoke;
    }
}
